package dao;

import entity.VegetablesTypes;
import util.IRowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * Created by Administrator on 2017/11/11.
 */
public class VegetableTypeDao {
    private DBHelper<VegetablesTypes> dbHelper=new DBHelper<>();
    //查询菜的种类
    public List<VegetablesTypes> query() throws SQLException, ClassNotFoundException {
        String sql="SELECT  v.name name,v.id id FROM vegetablestypes v;";
        IRowMapper<VegetablesTypes> rowMapper=new IRowMapper<VegetablesTypes>() {
            @Override
            public VegetablesTypes mapper(ResultSet rs) throws SQLException, ClassNotFoundException {
                  VegetablesTypes vt=new VegetablesTypes();
                    vt.setName(rs.getString("name"));
                    vt.setId(rs.getInt("id"));
                return vt;
            }
        };
        List<VegetablesTypes> list=dbHelper.queryAllHelper(rowMapper,sql);
        return list;
    }
    //关闭
    public void close()throws SQLException{
        dbHelper.close();
    }
}
